package com.shujia.mvc.controller;

import com.shujia.mvc.dao.UserDao;
import com.shujia.mvc.dao.UserDao1;
import com.shujia.mvc.dao.UserDaoInerace;
import com.shujia.mvc.service.UserService;
import com.shujia.mvc.service.UserServiceInterface;

import java.util.Scanner;

/**
 * 控制层
 * 和用户进行交互
 */
public class UserController {
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException {


        //从配置文件中获取dao    获取类对象

        //dao 层 实现类  com.shujia.mvc.dao.UserDao
        Class<?> aClass = Class.forName("com.shujia.mvc.dao.UserDao1");
        //通过反射创建对象
        UserDaoInerace userDao = (UserDaoInerace) aClass.newInstance();

        //创建业务层对象
        UserServiceInterface userService = new UserService(userDao);

        //创建控制层
        UserController userController = new UserController(userService);

        userController.login();

    }


    UserServiceInterface userService;

    public UserController(UserServiceInterface userService) {
        this.userService = userService;
    }

    //登录
    public void login() {
        Scanner scanner = new Scanner(System.in);

        System.out.println("请输入用户名：");
        String username = scanner.next();

        System.out.println("请输入用密码：");
        String password = scanner.next();


        String mes = userService.login(username, password);

        System.out.println(mes);

    }

    public void register() {
        Scanner scanner = new Scanner(System.in);

        System.out.println("请输入用户名：");
        String username = scanner.next();

        System.out.println("请输入密码：");
        String password = scanner.next();

        System.out.println("再次输入密码：");
        String password1 = scanner.next();

        String msg = userService.register(username, password, password1);
        System.out.println(msg);


    }
}
